package pe.edu.sisclas.model.dao.impl;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import pe.edu.sisclas.model.dao.LaboratorioDao;
import pe.edu.sisclas.model.dao.exception.DaoException;
import pe.edu.sisclas.model.domain.Laboratorio;

@Repository
public class LaboratorioDaoImpl implements LaboratorioDao {

	@Autowired
	private SessionFactory sessionFactory;
	
	
	@Override
	public Laboratorio getByName(String name) throws DaoException {
		try{
			Session session = getSessionFactory().getCurrentSession();
			Laboratorio laboratorio = (Laboratorio) session.createQuery("from Laboratorio l where l.numeroLaboratorio=:numero")
					.setParameter("numero", name)
					.uniqueResult();
			return laboratorio;
		}catch(Exception e){
			e.printStackTrace();
			throw DaoException.mensaje("Error al obtener Laboratorio");
		
		}
	}


	public SessionFactory getSessionFactory() {
		return sessionFactory;
	}


	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}
	
	

}
